{% extends 'wxchat/wxbase.html' %}{% load static %}
{% block extra %}
    {% include 'shopping/include/jssdk.html' %}
    <link rel="stylesheet" href="{% static 'css/foster.css' %}">
    <script type="text/javascript">
    wx.ready(function () {
        {% if not weixin_pay %}
        $('#pay_now_balance').on('click',function(){
            window.location.href = "{% url 'bath-pay-balance' %}?id=" + $("#id").text();
        });
        {% endif %}
        {% if weixin_pay %}
        $('#pay_now').on('click',function(){
            var params ={
              id: $("#id").text(),
              csrfmiddlewaretoken:'{{ csrf_token }}',
            }
           var ts = sessionStorage.getItem('bath_checkout');
           if(ts==null) {
               sessionStorage.setItem('bath_checkout', new Date().getTime());
           }else{
               var cur_ts = new Date().getTime();
               var diff = (cur_ts - Number(ts))/1000;
               if(diff < 20 ){
                   weui.alert('您刚才已经提交过，如果没有成功请30秒后再提交!');
                    return false;
               }
               sessionStorage.setItem('bath_checkout', cur_ts);
           }
           $.ajax({
              type: 'POST',
              url: '{% url "bath-pay" %}',
              dataType: 'json',
              data: params,
              timeout: 5000,
              success: function(data){
                  if(data.package !=undefined){
                      wxpay(data)
                  }
              },
              error: function(error){
                  window.location.href = "{% url 'dog-index' %}";
              }
            });
        });

        function wxpay(data){
            wx.chooseWXPay({
                  timestamp:data.timestamp,
                  nonceStr: data.nonceStr,
                  package:  data.package ,
                  signType: data.signType,
                  paySign:  data.paySign,
                  success: function(res){
                    if (res.errMsg == "chooseWXPay:ok") {
                        window.location.replace('{% url "foster-success" %}');
                    } else {
                       weui.alert('宠物洗浴订单支付失败!');
                    }
                  },
                   cancel: function(res) {

                   },
                   fail:function(res){

                   }
            });
        }
        {% endif %}
});

</script>
{% endblock extra %}

{% block container %}
<div class="weui-tab" id="tab">
    <div class="weui-tab__panel">
      <div class="weui-panel weui-panel_access">
       <div class="weui-panel__hd">
            <div class="weui-flex">
                <div><a href="javascript:window.history.back(-1)"><i class="icon iconfont icon-jiantou3 gray " ></i></a></div>
                <div class="weui-flex__item" style="text-align: center;"><span class="detail_title">{% if instance.status == 0 %} 收银台 {% else %} 洗浴订单详情 {% endif %}</span></div>
                <div ><a href="{% url 'dog-index' %}?next={{ request.get_full_path }}"><i class="icon iconfont icon-shangcheng10 pink r" ></i></a></div>
            </div>
       </div>
        <div class="weui-panel__bd">
            <div class="weui-form-preview">
                <div class="weui-form-preview__hd" style="text-align: right;line-height: 1.5em">
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">付款金额</label><span id="id" style="display: none" >{{ instance.id }}</span>
                        <em class="weui-form-preview__value  color-danger" id="total_cost_top" > {{ instance.total_fee|floatformat:"2" }} 元</em>
                    </div>
                </div>
                 <div class="weui-form-preview__hd" style="text-align: right;line-height: 1.5em">
                     {% if not weixin_pay %}
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">储值卡</label>
                        <em class="weui-form-preview__value "> -{{ instance.total_fee|floatformat:"2" }} 元</em>
                    </div>
                     {% elif weixin_pay %}
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">微信支付</label>
                        <em class="weui-form-preview__value  "> -{{ instance.total_fee|floatformat:"2" }} 元</em>
                    </div>
                     {% endif %}
                </div>
                <div class="weui-cells  cells_top">
                    {% if instance.status == 1 %}
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">订单号:</label></div>
                        <div class="weui-cell__bd">{{ instance.out_trade_no|default:'' }}</div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">支付时间:</label></div>
                        <div class="weui-cell__bd">{{ instance.pay_time|default:'' }}</div>
                    </div>
                    {% endif %}
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">洗浴台:</label></div>
                        <div class="weui-cell__bd">{{ instance.bath_room }}</div>
                    </div>
                    <div class="weui-cell weui-cell_vcode">
                        <div class="weui-cell__hd"><label for="" class="weui-label">宠物体重:</label></div>
                        <div class="weui-cell__bd">{{ instance.pet_weight }}</div>
                        <div class="weui-cell__ft">
                            <a href="javascript:;" class="weui-vcode-btn">斤</a>
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">开始时间:</label></div>
                        <div class="weui-cell__bd">
                            <p>{{ instance.start_time }}</p>
                        </div>
                        <div class="weui-cell__ft"></div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">结束时间:</label></div>
                        <div class="weui-cell__bd">
                            <p>{{ instance.end_time }}</p>
                        </div>
                        <div class="weui-cell__ft"></div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    </div>
    {% if instance.status == 0 %}
    <div class="weui-tabbar">
        {% if weixin_pay %}
         <a href="#" id="pay_now" class="weui-tabbar__item tabbar_item bg-primary" >
            <p class="weui-tabbar__label " style="font-size:18px;"> 立即支付 <span id="total_cost_bottom"> ¥ {{ instance.total_fee }}</span></p>
        </a>
        {% elif not weixin_pay%}
        <a href="#" id="pay_now_balance" class="weui-tabbar__item tabbar_item bg-warning" >
            <p class="weui-tabbar__label " style="font-size:18px;"> 立即支付 <span id="total_cost_bottom"> ¥ {{ instance.total_fee }}</span></p>
        </a>
        {% endif %}
    </div>
    {% endif %}
</div>

{% endblock container %}

{% block bottomjs %}
    {{ block.super }}
    <script>
    $(function(){
        
    })
    </script>
{% endblock bottomjs %}